package org.example.controller.SpringBoot300;

import org.example.util.console.ConsoleUtil;
import org.example.util.file.FileUtil;
import org.example.util.file.ImageUtil;
import org.example.util.file.PhotoTextUtil;
import org.example.util.log.Logac;

import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @auther admin闫
 * @Descriptopn 抖音封面三连图半自动化制作
 * @date 2024/4/6 1:28
 */
public class SpringBoot300DYFengMian {
    public static void main(String[] args) {
        String mubanDir="H:\\毕业设计工作目录\\batch_processing\\batch_processing\\封面模板\\";
        List<String> xiaYiPath = FileUtil.getXiaYiPath("H:\\毕业设计工作目录\\batch_processing\\batch_processing\\mudidir");
        int i=0;
        for (String s : xiaYiPath) {
            System.out.println(s);
            i++;
            List<String> xiaYiPath1 = FileUtil.getXiaYiPath(s);
            int y=0;
            String mubanToo="";
            for (String s1 : xiaYiPath1) {
                y++;
                String titleText="";
//---------------------------获取字符串部分----------------------------------------
                while (true) {
                    System.out.println("\u001B[36m" + FileUtil.getFileName(s1) + "\u001B[0m");

                    // 使用正则表达式提取连续的数字
                    Pattern pattern = Pattern.compile("\\d+");
                    Matcher matcher = pattern.matcher(FileUtil.getFileName(s1));
                    String bianhao = "";
                    // 循环匹配并输出结果
                    while (matcher.find()) {
                        bianhao = matcher.group();
                        System.out.println("\u001B[32m提取到的编号：" + bianhao + "\u001B[0m");
                    }
                    System.out.println("\u001B[34m输入名称\u001B[0m");
                    String mingcheng = ConsoleUtil.InputScanner();
                    if (mingcheng.length() > 9) {
                        System.out.println("\u001B[31m" + mingcheng + "：超过9个字！重新输入！\u001B[0m");
                        continue;
                    }
                    boolean b = ConsoleUtil.InputScannerOK();
                    titleText = "《" + bianhao + "基于SpringBoot的" + mingcheng + "》";
                    System.out.println("\u001B[35m最终名称：" + titleText + "\u001B[0m");
                    if (b) {
                        System.out.println("\u001B[32m已确认\u001B[0m");
                        break;
                    }
                }
//------------------------根据第几个设置高度部分--------------------------------------------
                int height=0; //高度
                switch (y) {
                    case 1:
                        height=440;
                        break;
                    case 2:
                        height=980;
                        break;
                    case 3:
                        height=1520;
                        break;
                }
//------------------------图片处理部分-----------------------------------------------------
                if (y==1){
                    try {
                        mubanToo= PhotoTextUtil.writeTextCenterWidth(mubanDir+i+".png",titleText,height,s+"\\整图.png");
                    } catch (IOException e) {
                        Logac.log("处理图片发生错误"+y);
                    }
                }else {
                    try {
                        mubanToo=PhotoTextUtil.writeTextCenterWidth(mubanToo,titleText,height,s+"\\整图.png");
                    } catch (IOException e) {
                        Logac.log("处理图片发生错误"+y);
                    }
                }
//-------------------------图片分割部分----------------------------------------------------
                if (y==3){
                    try {
                        ImageUtil.splitImage3(mubanToo,s);
                    } catch (IOException e) {
                        Logac.log("分割图片发送错误"+s);
                    }
                }
//---------------------------------------------------------------------------------------
            }
        }
    }

}
